// cates
const express = require('express')
const router = express.Router()

// 导入用户路由处理函数模块
const getartHandler = require("../router_handler/artcate")
// 导入处理路径的核心模块
const path = require('path')
// 1.导入验证数据的中间件
const expressJoi = require('@escook/express-joi')
// 2.导入需要的验证规则对象
const {reg_add_cate_schema,dele_cate_schema,add_cate_schema} = require('../schema/artcate')
// 导入解析 formdata 格式表单数据的包
const multer = require('multer')
const upload = multer({ dest: path.join(__dirname, '../uploads') })


// 获取文章分类列表数据的路由
router.get('/list',getartHandler.getArticleCates)
// 新增文章分类的路由
router.post('/add',expressJoi(reg_add_cate_schema),getartHandler.addcates)
// 根据id删除文章分类的路由
// router.get('/del/:id',expressJoi(dele_cate_schema),getartHandler.delecates)
router.get('/del',expressJoi(dele_cate_schema),getartHandler.delecates)
// 根据id获取文章分类列表的路由
router.get('/cates/:id',getartHandler.getArtCateById)
// 根据id修改文章分类的路由
router.put('/info',getartHandler.updateArtCateById)
// 发布新文章 upload.single上传单张图片
router.post('/artcle/add',upload.single('cover_img'),expressJoi(add_cate_schema),getartHandler.addArticle)
// 获取文章列表的路由
router.get('/article/list',getartHandler.getArticleList)
// 根据id获取文章详情的路由
router.get('/article/info',getartHandler.getArticleInfo)
// 根据id删除文章的路由
router.delete('/article/info',expressJoi(dele_cate_schema),getartHandler.deleArticle)
// 以下新增
// 根据职位类别（name）查职位的ID
router.get('/search',getartHandler.searchArticleInfo)
// 根据职位ID查职位列表
router.get('/idsearch',getartHandler.searchArticleInfoById)
module.exports = router